package com.niannian.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

	private Context context;

	public DatabaseHelper(Context context, String dbname, int dbversion) {
		super(context, dbname, null, dbversion);
		this.context = context;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if (oldVersion != newVersion) {
			if (oldVersion == 1) {
				db.execSQL("DROP TABLE IF EXISTS family_news_comment");
				db.execSQL("CREATE TABLE IF NOT EXISTS family_news_comment" + "(id INTEGER NOT NULL DEFAULT 0," + " author INTEGER NOT NULL DEFAULT 0,"
						+ " hasuid INTEGER NOT NULL DEFAULT 0," + " author_nickname TEXT NOT NULL DEFAULT ''," + " post INTEGER NOT NULL DEFAULT 0,"
						+ " author_avatar TEXT NOT NULL DEFAULT ''," + " info TEXT NOT NULL DEFAULT ''," + " aud TEXT NOT NULL DEFAULT '',"
						+ " created_time INTEGER NOT NULL DEFAULT 0," + " aud_len INTEGER NOT NULL DEFAULT 0," + " reply_to INTEGER NOT NULL DEFAULT 0,"
						+ " reply_to_nickname TEXT NOT NULL DEFAULT ''," + " PRIMARY KEY(hasuid,id,post))");
				oldVersion = 2;
			}
			if (oldVersion <= 2) {
				db.execSQL("DROP TABLE IF EXISTS greeting_receive");
				db.execSQL("CREATE TABLE IF NOT EXISTS greeting_receive" + "(id INTEGER NOT NULL DEFAULT 0," + " hasuid INTEGER NOT NULL DEFAULT 0,"
						+ " author INTEGER NOT NULL DEFAULT 0," + " author_nickname TEXT NOT NULL DEFAULT ''," + " author_avatar TEXT NOT NULL DEFAULT '',"
						+ " author_innername TEXT NOT NULL DEFAULT ''," + " info TEXT NOT NULL DEFAULT ''," + " pic TEXT NOT NULL DEFAULT '',"
						+ " aud TEXT NOT NULL DEFAULT ''," + " aud_len INTEGER NOT NULL DEFAULT 0," + " created_time INTEGER NOT NULL DEFAULT 0,"
						+ " type TEXT NOT NULL DEFAULT ''," + " receiver INTEGER NOT NULL DEFAULT 0," + " receiver_innername TEXT NOT NULL DEFAULT '',"
						+ " receiver_nickname TEXT NOT NULL DEFAULT ''," + " receiver_avatar TEXT NOT NULL DEFAULT '',"
						+ " sent_time INTEGER NOT NULL DEFAULT 0," + " rtype TEXT NOT NULL DEFAULT ''," + " PRIMARY KEY(hasuid,id))");
				oldVersion = 3;
			}
			if (oldVersion <= 3) {
				db.execSQL("DROP TABLE IF EXISTS family_news");
				db.execSQL("CREATE TABLE IF NOT EXISTS family_news" + "(id INTEGER NOT NULL DEFAULT 0," + " family INTEGER NOT NULL DEFAULT 0,"
						+ " hasuid INTEGER NOT NULL DEFAULT 0," + " author INTEGER NOT NULL DEFAULT 0," + " author_nickname TEXT NOT NULL DEFAULT '',"
						+ " author_avatar TEXT NOT NULL DEFAULT ''," + " info TEXT NOT NULL DEFAULT ''," + " pic TEXT NOT NULL DEFAULT '',"
						+ " aud TEXT NOT NULL DEFAULT ''," + " created_time INTEGER NOT NULL DEFAULT 0," + " pic_num INTEGER NOT NULL DEFAULT 0,"
						+ " aud_len INTEGER NOT NULL DEFAULT 0," + " PRIMARY KEY(hasuid,id))");
				oldVersion = 4;
			}
			if (oldVersion <= 4) {
				db.execSQL("DROP TABLE IF EXISTS greeting_receive");
				db.execSQL("CREATE TABLE IF NOT EXISTS greeting_receive" + "(id INTEGER NOT NULL DEFAULT 0," + " hasuid INTEGER NOT NULL DEFAULT 0,"
						+ " author INTEGER NOT NULL DEFAULT 0," + " author_nickname TEXT NOT NULL DEFAULT ''," + " author_avatar TEXT NOT NULL DEFAULT '',"
						+ " author_innername TEXT NOT NULL DEFAULT ''," + " info TEXT NOT NULL DEFAULT ''," + " pic TEXT NOT NULL DEFAULT '',"
						+ " aud TEXT NOT NULL DEFAULT ''," + " aud_len INTEGER NOT NULL DEFAULT 0," + " created_time INTEGER NOT NULL DEFAULT 0,"
						+ " type TEXT NOT NULL DEFAULT ''," + " receiver INTEGER NOT NULL DEFAULT 0," + " receiver_innername TEXT NOT NULL DEFAULT '',"
						+ " receiver_nickname TEXT NOT NULL DEFAULT ''," + " receiver_avatar TEXT NOT NULL DEFAULT '',"
						+ " sent_time INTEGER NOT NULL DEFAULT 0," + " rtype TEXT NOT NULL DEFAULT ''," + " sender INTEGER NOT NULL DEFAULT 0,"
						+ " is_checked TEXT NOT NULL DEFAULT ''," + " PRIMARY KEY(hasuid,id))");
				oldVersion = 5;
			}

			if (oldVersion <= 5) {
				db.execSQL("DROP TABLE IF EXISTS regards_tip");
				db.execSQL("CREATE TABLE IF NOT EXISTS regards_tip" + "(id INTEGER NOT NULL DEFAULT 0," + " hasuid INTEGER NOT NULL DEFAULT 0,"
						+ " creator INTEGER NOT NULL DEFAULT 0," + " title TEXT NOT NULL DEFAULT ''," + " spec_date INTEGER NOT NULL DEFAULT 0,"
						+ " notice_type INTEGER NOT NULL DEFAULT 0," + " desc TEXT NOT NULL DEFAULT ''," + " PRIMARY KEY(hasuid,id))");
				oldVersion = 6;
			}
			if (oldVersion <= 6) {
				db.execSQL("DROP TABLE IF EXISTS greeting_receive");
				db.execSQL("CREATE TABLE IF NOT EXISTS greeting_receive" + "(id INTEGER NOT NULL DEFAULT 0," + " hasuid INTEGER NOT NULL DEFAULT 0,"
						+ " author INTEGER NOT NULL DEFAULT 0," + " author_nickname TEXT NOT NULL DEFAULT ''," + " author_avatar TEXT NOT NULL DEFAULT '',"
						+ " author_innername TEXT NOT NULL DEFAULT ''," + " info TEXT NOT NULL DEFAULT ''," + " pic TEXT NOT NULL DEFAULT '',"
						+ " aud TEXT NOT NULL DEFAULT ''," + " aud_len INTEGER NOT NULL DEFAULT 0," + " created_time INTEGER NOT NULL DEFAULT 0,"
						+ " type TEXT NOT NULL DEFAULT ''," + " receiver INTEGER NOT NULL DEFAULT 0," + " receiver_innername TEXT NOT NULL DEFAULT '',"
						+ " receiver_nickname TEXT NOT NULL DEFAULT ''," + " receiver_avatar TEXT NOT NULL DEFAULT '',"
						+ " sent_time INTEGER NOT NULL DEFAULT 0," + " rtype TEXT NOT NULL DEFAULT ''," + " sender INTEGER NOT NULL DEFAULT 0,"
						+ " is_checked TEXT NOT NULL DEFAULT ''," + " reply_by INTEGER NOT NULL DEFAULT 0," + " PRIMARY KEY(hasuid,id))");

				db.execSQL("DROP TABLE IF EXISTS family_news");
				db.execSQL("CREATE TABLE IF NOT EXISTS family_news" + "(id INTEGER NOT NULL DEFAULT 0," + " family INTEGER NOT NULL DEFAULT 0,"
						+ " hasuid INTEGER NOT NULL DEFAULT 0," + " author INTEGER NOT NULL DEFAULT 0," + " author_nickname TEXT NOT NULL DEFAULT '',"
						+ " author_avatar TEXT NOT NULL DEFAULT ''," + " info TEXT NOT NULL DEFAULT ''," + " pic TEXT NOT NULL DEFAULT '',"
						+ " aud TEXT NOT NULL DEFAULT ''," + " news_type TEXT NOT NULL DEFAULT ''," + " created_time INTEGER NOT NULL DEFAULT 0,"
						+ " pic_num INTEGER NOT NULL DEFAULT 0," + " aud_len INTEGER NOT NULL DEFAULT 0," + " PRIMARY KEY(hasuid,id))");

				db.execSQL("DROP TABLE IF EXISTS news_info");
				db.execSQL("CREATE TABLE IF NOT EXISTS news_info" + "(id INTEGER NOT NULL DEFAULT 0," + " hasuid INTEGER NOT NULL DEFAULT 0,"
						+ " author_avatar TEXT NOT NULL DEFAULT ''," + " author_nickname TEXT NOT NULL DEFAULT ''," + " cmt_info TEXT NOT NULL DEFAULT '',"
						+ " cmt_aud TEXT NOT NULL DEFAULT ''," + " cmt_aud_len INTEGER NOT NULL DEFAULT 0," + " post INTEGER NOT NULL DEFAULT 0,"
						+ " post_pic TEXT NOT NULL DEFAULT ''," + " post_info TEXT NOT NULL DEFAULT ''," + " created_time INTEGER NOT NULL DEFAULT 0,"
						+ " news_type INTEGER NOT NULL DEFAULT 2," + " PRIMARY KEY(hasuid,id))");

				db.execSQL("DROP TABLE IF EXISTS regards_tip");

				db.execSQL("CREATE TABLE IF NOT EXISTS regards_tip" + "(id INTEGER NOT NULL DEFAULT 0," + " hasuid INTEGER NOT NULL DEFAULT 0,"
						+ " creator INTEGER NOT NULL DEFAULT 0," + " title TEXT NOT NULL DEFAULT ''," + " spec_date INTEGER NOT NULL DEFAULT 0,"
						+ " notice_type INTEGER NOT NULL DEFAULT 0," + " desc TEXT NOT NULL DEFAULT ''," + " is_triggered INTEGER NOT NULL DEFAULT 0,"
						+ " is_checked TEXT NOT NULL DEFAULT ''," + " is_f INTEGER NOT NULL DEFAULT 0," + "is_order INTEGER NOT NULL DEFAULT 0,"
						+ " PRIMARY KEY(hasuid,id))");

				oldVersion = 7;
			}

		}
	}
}
